package io.renren.modules.hospital.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.modules.hospital.entity.MedicalWithPatientEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import io.renren.modules.hospital.entity.BlEntity;
import io.renren.modules.hospital.service.BlService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author starry
 * @email 2495646304@qq.com
 * @date 2023-11-15 15:54:22
 */
@RestController
@RequestMapping("hospital/bl")
@Api(value = "病历接口", tags = "病历接口")
public class BlController {
    @Autowired
    private BlService blService;

    /**
     * 列表
     */
    @GetMapping(value = "/list")
    @ApiOperation("列表")
    //@RequiresPermissions("hospital:bl:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = blService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{blId}")
    @ApiOperation("信息")
    //@RequiresPermissions("hospital:bl:info")
    public R info(@PathVariable("blId") Integer blId) {
        BlEntity bl = blService.getById(blId);

        return R.ok().put("bl", bl);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation("保存")
    //@RequiresPermissions("hospital:bl:save")
    public R save(@RequestBody BlEntity bl) {
        blService.save(bl);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation("修改")
    //@RequiresPermissions("hospital:bl:update")
    public R update(@RequestBody BlEntity bl) {
        blService.updateById(bl);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation("删除")
    //@RequiresPermissions("hospital:bl:delete")
    public R delete(@RequestBody Integer[] blIds) {
        blService.removeByIds(Arrays.asList(blIds));

        return R.ok();
    }

    @GetMapping("/medical_by_ysId")
    @ApiOperation("根据当前的处理医生的id获取所有的病历实体")
    public R getMedicalByYsId(@RequestParam("ysId") Integer ysId) {
        List<BlEntity> list;
        list=blService.getMedicalByYsId(ysId);
        return R.ok().put("page",list);
    }

    @GetMapping("/medical_with_patientInfo")
    @ApiOperation("获取除当天更新之外的病历 根据当前的处理医生的id获取所有的病历实体并联合查询出患者的个人信息")
    public R  getMedicalWithPatientInfo(Integer ysId){
        List<MedicalWithPatientEntity> list=blService.getMedicalWithPatientInfo(ysId);
        return R.ok().put("page",list);
    }

    @GetMapping("/medical_today")
    @ApiOperation("获取当天更新的病历 根据当前的处理医生的id获取所有的病历实体并联合查询出患者的个人信息")
    public R   getTodayMedical(Integer ysId){
        List<MedicalWithPatientEntity> list=blService.getTodayMedical(ysId);
        return R.ok().put("page",list);
    }
}
